package com.zxy.ziems.server.energy.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zxy.ziems.server.board.pojo.vo.DosageVo;
import com.zxy.ziems.server.classify.pojo.param.ClassifyMeasureDataHourParam;
import com.zxy.ziems.server.device.pojo.vo.DeviceMeasureDataHourVO;
import com.zxy.ziems.server.domain.DeviceMeasureDataIncrementHour;
import com.zxy.ziems.server.energy.pojo.dto.DeviceMeasureDataDayDTO;
import com.zxy.ziems.server.energy.pojo.dto.DeviceMeasureDayCostDTO;
import com.zxy.ziems.server.energy.pojo.entity.DeviceMeasureDataDayEntity;
import com.zxy.ziems.server.mybatis.core.mapper.BaseMapperX;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * @Copyright (C),
 * @ClassName: DeviceMeasureDataIncrementHourMapper
 * @Author: yanzhiwei
 * @Description:
 * @Date: 2024/4/7 14:25
 */
@Mapper
public interface DeviceMeasureDataIncrementHourMapper extends BaseMapperX<DeviceMeasureDataIncrementHour> {


    /**
     * 类天趋势（时间段内，偶数时间段数据值，取时间值为%y%m%d %H）
     *
     * @param startDate
     * @param endDate
     * @param classifyIds
     * @return
     */
    List<DosageVo> classDayTrend(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate,
                                 @Param("classifyIds") List<String> classifyIds);

    IPage<DeviceMeasureDataHourVO> pageList(@Param("page") IPage<DeviceMeasureDataHourVO> page,
                                            @Param("param") ClassifyMeasureDataHourParam pageParam);

    DeviceMeasureDataHourVO getVO(@Param("param") ClassifyMeasureDataHourParam param);

    List<DeviceMeasureDayCostDTO> getDayPrice(@Param("startDateTime") LocalDateTime startDateTime, @Param("endDateTime") LocalDateTime endDateTime);

    BigDecimal getDayPriceByDeviceAndDataType(@Param("date") LocalDate date, @Param("dataTypeId") String dataTypeId, @Param("deviceId") String deviceId);

    List<DeviceMeasureDataDayDTO> getMeasureDataDayPriceByDeviceAndDataType(@Param("dateSet") Set<LocalDate> dateSet, @Param("dataTypeId") String dataTypeId, @Param("deviceId") String deviceId);

    List<DeviceMeasureDataIncrementHour> getChangeData(@Param("deviceId") String deviceId, @Param("dataTypeId") String dataTypeId,
                                                       @Param("measureTime") LocalDateTime measureTime, @Param("measureValue") BigDecimal measureValue);

    IPage<DeviceMeasureDataHourVO> getMeasureData(@Param("page") IPage<DeviceMeasureDataHourVO> page, @Param("param") ClassifyMeasureDataHourParam pageParam);

    /* 分页查询
     * @param page
     * @param param
     * @return
     */
    IPage<DeviceMeasureDataIncrementHour> queryPageListByDeviceId(@Param("page") IPage<DeviceMeasureDataIncrementHour> page,
                                                                  @Param("startDate") LocalDateTime startDate,
                                                                  @Param("endDate") LocalDateTime endDate,
                                                                  @Param("deviceIdList") List<String> deviceIdList);

    // 动态更新已有数据（忽略 null 字段）
    int updateDeviceMeasureData(@Param("deviceId") String deviceId,
                                @Param("measureTime") LocalDateTime measureTime,
                                @Param("measureValue") BigDecimal measureValue,
                                @Param("avgValue") BigDecimal avgValue,
                                @Param("incrementValue") BigDecimal incrementValue,
                                @Param("incrementCost") BigDecimal incrementCost,
                                @Param("updateUserId") String updateUserId,
                                @Param("updateTime") LocalDateTime updateTime);


    DeviceMeasureDataIncrementHour selectByDeviceIdAndTime(
            @Param("deviceId") String deviceId,
            @Param("measureTime") LocalDateTime measureTime);
}
